package mulegame;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.MatteBorder;
import javax.swing.border.TitledBorder;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.util.Hashtable;
import javax.swing.AbstractAction;
import javax.swing.JSlider;
import javax.swing.JRadioButton;
import javax.swing.ButtonGroup;
import java.awt.event.ComponentAdapter;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;

/**
 * Creates the Store Screen with players and different buying options. will add logic and actionlisteners later
 * @author Briam
 *
 */

public class StoreScreen extends TimedScreen {
    private JLabel lblTimer;
    private int timeleft;
    private Store.ItemType item;
    private final ButtonGroup buttonGroup = new ButtonGroup();
    private JRadioButton rdbtnBuy;
    private JRadioButton rdbtnSell;
    private JPanel panelAction;
    private TitledBorder actionBorder;
    private JSlider slider;
    private JButton btnCommit;
    private Store store;
    private Player player;
    private int quantity;
    
    
	/**
	 * Create the Store screen with player scores, choices to gamble or return to Town
	 * path images of different options with action listeners 
	 */
    
	public StoreScreen(GraphicsControl ctrl, int duration, Store store, Player p) {
        super(ctrl, duration);
        this.store = store;
        player = p;
        timeleft = (duration/1000);
        item = null;
	
		setSize(new Dimension(900, 600));
		setBorder(new MatteBorder(4, 4, 4, 4, (Color) new Color(0, 0, 0)));
		setLayout(null);

		int numOfPlayers = control.getNumPlayers();
		
		JLabel lblMainTitle = new JLabel("Coffee Mule");
		lblMainTitle.setBounds(175, 11, 563, 51);
		lblMainTitle.setForeground(new Color(165, 42, 42));
		lblMainTitle.setHorizontalAlignment(SwingConstants.CENTER);
		lblMainTitle.setFont(new Font("Batang", Font.BOLD, 45));
		add(lblMainTitle);

		lblTimer = new JLabel("XX Seconds");
		lblTimer.setForeground(Color.RED);
		lblTimer.setBorder(new LineBorder(Color.BLACK, 2));
		lblTimer.setFont(new Font("Times New Roman", Font.PLAIN, 29));
		lblTimer.setHorizontalAlignment(SwingConstants.CENTER);
		lblTimer.setBounds(708, 10, 168, 83);
		add(lblTimer);
		
		JLabel lblLogoSMALL = new JLabel("");
		lblLogoSMALL.setIcon(new ImageIcon("src/mulegame/Images/LogoSmall.jpg"));
		lblLogoSMALL.setBorder(new LineBorder(new Color(0, 0, 0), 2));
		lblLogoSMALL.setBounds(20, 11, 97, 93);
		add(lblLogoSMALL);
		
		JPanel storeBorder = new JPanel();
		storeBorder.setBorder(new TitledBorder(null, "Coffee Store",
				TitledBorder.LEADING, TitledBorder.TOP, null, null));
		storeBorder.setBounds(223, 83, 471, 295);
		add(storeBorder);
		storeBorder.setLayout(null);
		
		JPanel theStore = new JPanel();
		theStore.setLayout(null);
		theStore.setBounds(10, 27, 450, 250);
		storeBorder.add(theStore);
		
		JButton btnMuleBean = new JButton("");
		btnMuleBean.setToolTipText("Bean Mule");
		btnMuleBean.setIcon(new ImageIcon("src/mulegame/Images/storebeanMule.jpg"));
		btnMuleBean.setBorderPainted(true);
		btnMuleBean.setBorder(new LineBorder(Color.BLACK, 2));
		btnMuleBean.setBounds(0, 0, 155, 109);
		btnMuleBean.addActionListener(new MuleBeanAction());
		theStore.add(btnMuleBean);
		
		JButton btnMuleEnergy = new JButton("");
		btnMuleEnergy.setToolTipText("Energy Mule");
		btnMuleEnergy.setIcon(new ImageIcon("src/mulegame/Images/storeenergyMule2.jpg"));
		btnMuleEnergy.setBorderPainted(true);
		btnMuleEnergy.setBorder(new LineBorder(Color.BLACK, 2));
		btnMuleEnergy.setBounds(171, 0, 109, 78);
		btnMuleEnergy.addActionListener(new MuleEnergyAction());
		
		JLabel lblBeanMule = new JLabel("Bean Mule");
		lblBeanMule.setHorizontalAlignment(SwingConstants.CENTER);
		lblBeanMule.setFont(new Font("MV Boli", Font.PLAIN, 10));
		lblBeanMule.setBounds(30, 108, 90, 20);
		theStore.add(lblBeanMule);
		theStore.add(btnMuleEnergy);
		
		JButton btnMuleFood = new JButton("");
		btnMuleFood.setToolTipText("Food Mule");
		btnMuleFood.setIcon(new ImageIcon("src/mulegame/Images/storefoodMule.jpg"));
		btnMuleFood.setBorderPainted(true);
		btnMuleFood.setBorder(new LineBorder(Color.BLACK, 2));
		btnMuleFood.setBounds(295, 0, 155, 109);
		btnMuleFood.addActionListener(new MuleFoodAction());
		
		JLabel lblEnergyMule = new JLabel("Energy Mule");
		lblEnergyMule.setBounds(181, 75, 90, 20);
		theStore.add(lblEnergyMule);
		lblEnergyMule.setHorizontalAlignment(SwingConstants.CENTER);
		lblEnergyMule.setFont(new Font("MV Boli", Font.PLAIN, 10));
		theStore.add(btnMuleFood);
		
		JButton btnBean = new JButton("");
		btnBean.setToolTipText("Beans");
		btnBean.setIcon(new ImageIcon("src/mulegame/Images/Store bean.jpg"));
		btnBean.setBorderPainted(true);
		btnBean.setBorder(new LineBorder(Color.BLACK, 2));
		btnBean.setBounds(10, 170, 113, 79);
		btnBean.addActionListener(new BeanAction());
		
		JLabel lblFoodMule = new JLabel("Food Mule");
		lblFoodMule.setHorizontalAlignment(SwingConstants.CENTER);
		lblFoodMule.setFont(new Font("MV Boli", Font.PLAIN, 10));
		lblFoodMule.setBounds(330, 108, 90, 20);
		theStore.add(lblFoodMule);
		theStore.add(btnBean);
		
		JButton btnEnergy = new JButton("");
		btnEnergy.setToolTipText("Energy");
		btnEnergy.setIcon(new ImageIcon("src/mulegame/Images/Store energy.jpg"));
		btnEnergy.setBorderPainted(true);
		btnEnergy.setBorder(new LineBorder(Color.BLACK, 2));
		btnEnergy.setBounds(186, 191, 80, 57);
		btnEnergy.addActionListener(new EnergyAction());
		
		JLabel lblBeans = new JLabel("Beans");
		lblBeans.setHorizontalAlignment(SwingConstants.CENTER);
		lblBeans.setFont(new Font("MV Boli", Font.PLAIN, 10));
		lblBeans.setBounds(30, 149, 90, 20);
		theStore.add(lblBeans);
		theStore.add(btnEnergy);
		
		JButton btnFood = new JButton("");
		btnFood.setToolTipText("Food");
		btnFood.setIcon(new ImageIcon("src/mulegame/Images/Store food.jpg"));
		btnFood.setBorderPainted(true);
		btnFood.setBorder(new LineBorder(Color.BLACK, 2));
		btnFood.setBounds(328, 170, 113, 79);
		btnFood.addActionListener(new FoodAction());
		theStore.add(btnFood);
		
		JLabel lblFood = new JLabel("Food");
		lblFood.setHorizontalAlignment(SwingConstants.CENTER);
		lblFood.setFont(new Font("MV Boli", Font.PLAIN, 10));
		lblFood.setBounds(328, 152, 90, 20);
		theStore.add(lblFood);
		
		JButton btnCashier = new JButton("");
		btnCashier.setIcon(new ImageIcon("src/mulegame/Images/storecashier.jpg"));
		btnCashier.setBorderPainted(true);
		btnCashier.setBorder(new LineBorder(Color.BLACK, 2));
		btnCashier.setBounds(187, 94, 77, 93);
		theStore.add(btnCashier);
		
		JButton btnBannerLeft = new JButton("");
		btnBannerLeft.setBorderPainted(true);
		btnBannerLeft.setBorder(null);
		btnBannerLeft.setBounds(0, 127, 187, 25);
		theStore.add(btnBannerLeft);
		
		JButton btnBannerRight = new JButton("");
		btnBannerRight.setBorderPainted(true);
		btnBannerRight.setBorder(null);
		btnBannerRight.setBounds(264, 127, 186, 25);
		theStore.add(btnBannerRight);
		
		JLabel lblEnergy = new JLabel("Energy");
		lblEnergy.setHorizontalAlignment(SwingConstants.CENTER);
		lblEnergy.setFont(new Font("MV Boli", Font.PLAIN, 10));
		lblEnergy.setBounds(191, 275, 90, 20);
		storeBorder.add(lblEnergy);
		
		panelAction = new JPanel();
		actionBorder = new TitledBorder(null, "Buy/Sell Stuff", TitledBorder.LEADING, TitledBorder.TOP, null, null);
		panelAction.setBorder(actionBorder);
		panelAction.setBounds(697, 116, 181, 262);
		add(panelAction);
		panelAction.setLayout(null);
		
		slider = new JSlider();
		slider.setPaintTicks(true);
		slider.setPaintLabels(true);
		slider.setMinorTickSpacing(1);
//		slider.setMajorTickSpacing(10);
		slider.setValue(0);
		slider.setMinimum(0);
		slider.setMaximum(20);
		slider.setSnapToTicks(true);
		slider.setOrientation(SwingConstants.VERTICAL);
//		slider.setFont(new Font("MV Boli", Font.PLAIN, 20));
		slider.setBounds(10, 35, 96, 200);
		slider.addChangeListener(new SliderChangeListener());
		slider.setEnabled(false);
        Hashtable currentTable = new Hashtable();
        currentTable.clear();
        currentTable.put(0, new JLabel("0"));
        currentTable.put(10, new JLabel("10"));
        currentTable.put(20, new JLabel("20"));
        slider.setLabelTable(currentTable);
        slider.setPaintLabels(true);
		panelAction.add(slider);
		
		rdbtnBuy = new JRadioButton("Buy",true);
		buttonGroup.add(rdbtnBuy);
		rdbtnBuy.setBounds(112, 100, 63, 23);
		rdbtnBuy.addActionListener(new RadioButtonListener());
		rdbtnBuy.setEnabled(false);
		panelAction.add(rdbtnBuy);
		
		rdbtnSell = new JRadioButton("Sell");
		buttonGroup.add(rdbtnSell);
		rdbtnSell.setBounds(112, 138, 63, 23);
		rdbtnSell.addActionListener(new RadioButtonListener());
		rdbtnSell.setEnabled(false);
		panelAction.add(rdbtnSell);

		btnCommit = new JButton(new BuyButtonAction());
		btnCommit.setText("COMMIT");
		btnCommit.setFont(new Font("Times New Roman", Font.PLAIN, 29));
		btnCommit.setBorderPainted(true);
		btnCommit.setBorder(new BevelBorder(BevelBorder.RAISED, null, null, null,
		                    null));
		btnCommit.setBounds(30, 500, 200, 83);
		btnCommit.setEnabled(false);
		add(btnCommit);
		
		JButton btnReturn = new JButton(new BackToTownAction());
		btnReturn.setText("Return To Town");
		btnReturn.setFont(new Font("Times New Roman", Font.PLAIN, 20));
		btnReturn.setBorderPainted(true);
		btnReturn.setBorder(new BevelBorder(BevelBorder.RAISED, null, null,

		                    null, null));
		btnReturn.setBounds(697, 500, 168, 83);
		add(btnReturn);
		
        timeleft++;
        timerTick();
	}
	/**
	 * makes timer tick down and dispalys 
	 */
	@Override
	public void timerTick(){
	    //decrement timeleft and update the timer lable
	    Integer time = timeleft--;
	    lblTimer.setText(time.toString() + " Seconds");
        invalidate();//this should be the last call in this method
	}
	
    /**
     * 
     */
	@Override
	public void timerTimeOut(){
	     //do nothing, MainScreen's timer will take care of changing the screen   
	}
	
	/**
	 * changes function of commit button based on case in store. for food, energy, or ore determines price of food,
	 *  and either buys or sells food and updates display. also gets the price of different mules and lets player 
	 *  buy them. Updates commit button with price. 
	 */
	private void changeCommitButton(){
	    int price = 0;
        Hashtable currentTable = new Hashtable();
        currentTable.clear();
        
	    switch(item){
	    case FOOD:
	         price = quantity * store.costFood;
	         
	         currentTable.put(0, new JLabel("0"));

	         if(rdbtnBuy.isSelected()){
		         currentTable.put(store.getFood()/2, new JLabel(Integer.toString(store.getFood()/2)));
		         currentTable.put(store.getFood(),new JLabel(Integer.toString(store.getFood())));
	         } else {
		         currentTable.put(player.getFood()/2, new JLabel(Integer.toString(player.getFood()/2)));
		         currentTable.put(player.getFood(),new JLabel(Integer.toString(player.getFood())));
	         }
	         
	         slider.setLabelTable(currentTable);
	         slider.setPaintLabels(true);
	         panelAction.repaint();
	         
	         break;
	    case ENERGY:
	         price = quantity * store.costEnergy;

	         currentTable.put(0, new JLabel("0"));
	         
	         if(rdbtnBuy.isSelected()){
		         currentTable.put(store.getEnergy()/2, new JLabel(Integer.toString(store.getEnergy()/2)));
		         currentTable.put(store.getEnergy(),new JLabel(Integer.toString(store.getEnergy())));
	         } else {
		         currentTable.put(player.getEnergy()/2, new JLabel(Integer.toString(player.getEnergy()/2)));
		         currentTable.put(player.getEnergy(),new JLabel(Integer.toString(player.getEnergy())));
	         }
	         
	         slider.setLabelTable(currentTable);
	         slider.setPaintLabels(true);
	         panelAction.repaint();
	         
	         break;
	    case ORE:
	         price = quantity * store.costSmithore;
	         
	         currentTable.put(0, new JLabel("0"));
	         
	         if(rdbtnBuy.isSelected()){
		         currentTable.put(store.getOre()/2, new JLabel(Integer.toString(store.getOre()/2)));
		         currentTable.put(store.getOre(),new JLabel(Integer.toString(store.getOre())));
	         } else {
		         currentTable.put(player.getOre()/2, new JLabel(Integer.toString(player.getOre()/2)));
		         currentTable.put(player.getOre(),new JLabel(Integer.toString(player.getOre())));
	         }     

	         slider.setLabelTable(currentTable);
	         slider.setPaintLabels(true);
	         panelAction.repaint();
	         
	         break;
	    case MULE_FOOD:
	         price = store.getMuleCost(Mule.FOOD);
	         break;
	    case MULE_ENERGY:
	         price = store.getMuleCost(Mule.ENERGY);
	         break;
	    case MULE_ORE:
	        price = store.getMuleCost(Mule.ORE);
	        break;
	    default:
	        //error, so log it
	        Logger.println("changeCommitButton: unknown item type");
	        break;
	    }
	    btnCommit.setText("COMMIT [" + Integer.toString(price) + "]");
	    
	}
	
	/**
     * controls the clicking sound by playing an audiofile
     */
    public void doClickSound() {
    	String soundName = "src/mulegame/Sounds/click.wav";    
    	AudioInputStream audioInputStream = null;
		try {
			audioInputStream = AudioSystem.getAudioInputStream(new File(soundName).getAbsoluteFile());
		} catch (UnsupportedAudioFileException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	Clip clip = null;
		try {
			clip = AudioSystem.getClip();
		} catch (LineUnavailableException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	try {
			clip.open(audioInputStream);
		} catch (LineUnavailableException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
    	clip.start();
    }    
    public int getQuantity(){
        return slider.getValue();
    }
    
    public Store.ItemType getItemType(){
        return item;
    }
    
    /**
	 * creates action listener for going back to town button
	 * @author AREA 29
	 *
	 */
	private class BackToTownAction extends AbstractAction{
	    @Override
	    public void actionPerformed(ActionEvent e){
	    	doClickSound();
	        control.backToTownScreen();   
	    }
	}

	private class BuyButtonAction extends AbstractAction{
        @Override
        public void actionPerformed(ActionEvent evnt){
            if(rdbtnBuy.isSelected()){
                control.buyClicked();
                switch(item){
                case FOOD:
                    slider.setMaximum(store.getFood());
                    break;
                case ENERGY:
                    slider.setMaximum(store.getEnergy());
                    break;
                case ORE:
                    slider.setMaximum(store.getOre());
                    break;
                default:
                    break;
                }
            } else {
                control.sellClicked();
                switch(item){
                case FOOD:
                    slider.setMaximum(player.getFood());
                    break;
                case ENERGY:
                    slider.setMaximum(player.getEnergy());
                    break;
                case ORE:
                    slider.setMaximum(player.getOre());
                    break;
                default:
                    break;
                }
            }
        }
    }
	
    /**
     * Provides action listener for the sliders to buy/sell food,energy, or ore. 
     * @author AREA 29
     *
     */
    private class RadioButtonListener extends AbstractAction{
        @Override
        public void actionPerformed(ActionEvent evnt){
            boolean buySelected = evnt.getSource() == rdbtnBuy;
            String borderPrefix = buySelected ? "Buy " : "Sell ";
            String borderSuffix = "";
            switch(item){
            case FOOD:
                borderSuffix = "Food";
                if(buySelected){
                    slider.setMaximum(store.getFood());
                } else {
                    slider.setMaximum(player.getFood());
                }
                break;
            case ORE:
                borderSuffix = "Beans";
                if(buySelected){
                    slider.setMaximum(store.getOre());   
                } else {
                    slider.setMaximum(player.getOre());
                }
                break;
            case ENERGY:
                borderSuffix = "Energy";
                if(buySelected){
                    slider.setMaximum(store.getEnergy());
                } else {
                    slider.setMaximum(player.getEnergy());
                }
                break;
            case MULE_FOOD:
                borderSuffix = "Food Mule";
                break;
            case MULE_ENERGY:
                borderSuffix = "Energy Mule";
                break;
            case MULE_ORE:
                borderSuffix = "Bean Mule";
                break;
            default:
                Logger.println("unknown store case");
                break;
            }
            actionBorder.setTitle(borderPrefix + borderSuffix);
            panelAction.repaint();
            changeCommitButton();
        }
    }
    
    /**
     * provides action listener for buying a bean mule
     * @author AREA 29
     *
     */
	private class MuleBeanAction extends AbstractAction{
	     @Override
	     public void actionPerformed(ActionEvent evnt){
	         doClickSound();
	         item = Store.ItemType.MULE_ORE;
	         rdbtnBuy.setSelected(true);
	         rdbtnSell.setEnabled(false);
	         slider.setEnabled(false);
	         btnCommit.setEnabled(true);
	         actionBorder.setTitle("Buy Bean Mule");
	         control.setInstructionText("The Bean Mule costs " + control.getMuleCost(Mule.ORE) + ". Click COMMIT to buy.  Place your Mule before your time is up, or it will run away!!");
	         panelAction.repaint();
	         changeCommitButton();
	     }
	}
	
	/**
     * provides action listener for buying an energy mule
     * @author AREA 29
     *
     */
	private class MuleEnergyAction extends AbstractAction{
	     @Override
	     public void actionPerformed(ActionEvent evnt){
	         doClickSound();
	         item = Store.ItemType.MULE_ENERGY;
	         rdbtnBuy.setSelected(true);
	         rdbtnSell.setEnabled(false);
	         slider.setEnabled(false);
	         btnCommit.setEnabled(true);
	         actionBorder.setTitle("Buy Energy Mule");
	         control.setInstructionText("The Energy Mule costs " + control.getMuleCost(Mule.ENERGY) + ". Click COMMIT to buy.  Place your Mule before your time is up, or it will run away!!");
	         panelAction.repaint();
	         changeCommitButton();
	     }
	}
	
	/**
     * provides action listener for buying an food mule
     * @author AREA 29
     *
     */
	private class MuleFoodAction extends AbstractAction{
	     @Override
	     public void actionPerformed(ActionEvent evnt){
	         doClickSound();
             item = Store.ItemType.MULE_FOOD;
	         rdbtnBuy.setSelected(true);
	         rdbtnSell.setEnabled(false);
	         slider.setEnabled(false);
	         btnCommit.setEnabled(true);
	         actionBorder.setTitle("Buy Food Mule");
	         control.setInstructionText("The Food Mule costs " + control.getMuleCost(Mule.FOOD) + ". Click COMMIT to buy.  Place your Mule before your time is up, or it will run away!!");
	         panelAction.repaint();
	         changeCommitButton();
	     }
	}
	
	/**
	 * provides action listener for if player wants to buy/sell beans and sets slider to maximum amount they can
	 * buy/sell
	 * @author AREA 29
	 *
	 */
	private class BeanAction extends AbstractAction{
	     @Override
	     public void actionPerformed(ActionEvent evnt){
	         doClickSound();
	         item = Store.ItemType.ORE;
	         rdbtnSell.setEnabled(true);
	         rdbtnBuy.setEnabled(true);
	         slider.setEnabled(true);
	         btnCommit.setEnabled(true);
	         
	         if(rdbtnBuy.isSelected()){
	             slider.setMaximum(store.getOre());
	             actionBorder.setTitle("Buy Beans");
	             panelAction.repaint();
	         } else {
	             slider.setMaximum(player.getOre());
	             actionBorder.setTitle("Sell Beans");
	             panelAction.repaint();
	         }
	         
	         if (slider.getMaximum() == 0) {
					control.setInstructionText("There are no Beans in the Store to sell! Sorry!");
				} else {
					control.setInstructionText("The cost of Beans is "
							+ control.getOreCost() + " per unit.");
				}
            changeCommitButton();
	     }
	}
	
	/**
	 * provides action listener for if player wants to buy/sell energy and sets slider to maximum amount they can
	 * buy/sell
	 * @author AREA 29
	 *
	 */
	private class EnergyAction extends AbstractAction{
	     @Override
	     public void actionPerformed(ActionEvent evnt){
	         doClickSound();
	         item = Store.ItemType.ENERGY;
	         rdbtnSell.setEnabled(true);
	         rdbtnBuy.setEnabled(true);	         
	         slider.setEnabled(true);
	         btnCommit.setEnabled(true);
	         
	         if(rdbtnBuy.isSelected()){
	             slider.setMaximum(store.getEnergy());
	             actionBorder.setTitle("Buy Energy");
	             panelAction.repaint();
	         } else {
	             slider.setMaximum(player.getEnergy());
	             actionBorder.setTitle("Sell Energy");
	             panelAction.repaint();
	         }
	         
	         if (slider.getMaximum() == 0) {
					control.setInstructionText("There is no Energy in the Store to sell! Sorry!");
				} else {
					control.setInstructionText("The cost of Energy is "
							+ control.getEnergyCost() + " per unit.");
				}
            changeCommitButton();
	     }
	}
	
	/**
	 * provides action listener for if player wants to buy/sell food and sets slider to maximum amount they can
	 * buy/sell
	 * @author AREA 29
	 *
	 */
	private class FoodAction extends AbstractAction{
	     @Override
	     public void actionPerformed(ActionEvent evnt){
	         doClickSound();
	         item = Store.ItemType.FOOD;
	         rdbtnSell.setEnabled(true);
	         slider.setEnabled(true);
	         rdbtnBuy.setEnabled(true);	         
	         btnCommit.setEnabled(true);
	         
	         if(rdbtnBuy.isSelected()){
	             slider.setMaximum(store.getFood());
	             actionBorder.setTitle("Buy Food");
	             panelAction.repaint();
	         } else {
	             slider.setMaximum(player.getFood());
	             actionBorder.setTitle("Sell Food");
	             panelAction.repaint();
	         }
	         
	         if (slider.getMaximum() == 0) {
					control.setInstructionText("There is no Food in the Store to sell! Sorry!");
				} else {
					control.setInstructionText("The cost of Food is "
							+ control.getFoodCost() + " per unit.");
				}
            changeCommitButton();
	         
	     }
	}
	
	/**
	 * provides action listener for slider 
	 * @author AREA 29
	 *
	 */
	private class SliderChangeListener extends ComponentAdapter implements ChangeListener{
	    
        public void stateChanged(ChangeEvent evnt){
               quantity = ((JSlider)evnt.getSource()).getValue();
               changeCommitButton();
        }
	}
}
